package com.future.mapper;

import com.future.entity.Monster;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <P>
 *
 * </p>
 *
 * @author yinhao
 * @version 1.0
 * @since 2024/9/10 13:35
 */
public interface MonsterAnnotation {

    @Insert(value = "insert into t_monster(name,age,birthday,gender,salary,email) values (#{name},#{age},#{birthday},#{gender},#{salary},#{email})")
    // keyProperty：返回主键的属性名
    // keyColumn：对应的表的字段
    // 如果keyProperty和keyColumn都为空，则返回自增主键
    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")
    void addMonster(Monster monster);

    @Delete("delete from t_monster where id = #{monsterId}")
    void deleteMonsterById(Integer monsterId);

    @Update("update t_monster set name=#{name},age=#{age},birthday=#{birthday},gender=#{gender},salary=#{salary},email=#{email} where id=#{id}")
    void updateMonster(Monster monster);

    @Select("select * from t_monster where id = #{monsterId}")
    Monster getMonsterById(Integer monsterId);

    @Select("select * from t_monster")
    List<Monster> findAllMonster();
}
